import java.util.ArrayList;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;


public class GamePlay {
	
	private Image background1 = null;
	private Image background2 = null;
	private float back1X;
	private float back2X;
	
	private float speed = 0.2f;
	
	private Bubble bubble = null;
	private ArrayList<Food> food = null;
	private ArrayList<Obstacle> obstacles = null;
	
	private static final float GRAVITY = 9.8f;
	private static final int BACKGROUND_WIDTH = 1067;
	
	public GamePlay() throws SlickException{
		initialise();
	}
	
	public void initialise() throws SlickException{
		background1 = new Image("assets/gameplay/background.png").getScaledCopy(1.042f);
		background2 = new Image("assets/gameplay/background.png").getScaledCopy(1.042f);
		
		System.out.println(background1.getWidth());
		bubble = new Bubble();
		food = new ArrayList<Food>();
		obstacles = new ArrayList<Obstacle>();
		back1X = 0f;
		back2X = back1X + background2.getWidth();
	}
	
	public void update(GameContainer gc, int delta){
		moveBackground(delta);
		/** TODO 
		 * move the bubble
		 * move the food and walls
		 * test collisions
		 * update score
		 */
	}
	
	private void moveBackground(int delta){
		back1X -= speed * delta;
		back2X -= speed * delta;
		if(back1X < -BACKGROUND_WIDTH){
			back1X = BACKGROUND_WIDTH;
		}
		if(back2X < -BACKGROUND_WIDTH){
			back2X = BACKGROUND_WIDTH;
		}
		
		
	}
	
	public void render(GameContainer gc, Graphics g){
		background1.draw(back1X, 0f);
		background2.draw(back2X, 0f);
		bubble.render();
	}

}
